import { Body, Controller, Get, Param, Put, UseGuards } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { MedinfoService } from './medinfo.service';
import { medinfo } from './medinfo.entity';
import { JwtAuthGuard } from 'src/auth/auth.guard';

@Controller('medinfo')
export class MedinfoController {
  constructor(
    private readonly configService: ConfigService,
    private readonly medinfoService: MedinfoService,
  ) {}

  @Get('page/:id')
  getPage(@Param('id') id: number) {
    return this.medinfoService.getPage(id);
  }

  @Get('page/name/:name')
  async getPageByName(@Param('name') name: string) {
    let res: any = await this.medinfoService.getPageIDByName(name);
    return { id: res };
  }

  @Get('length')
  getMedinfoTableLength() {
    return this.medinfoService.getMedinfoTableLength();
  }

  @Put('update/zhongyoo/:id')
  @UseGuards(JwtAuthGuard)
  async updateZhongyoo(
    @Param('id') id: number,
    @Body() updateData: Partial<medinfo>, // 直接使用实体的 Partial 类型
  ) {
    console.log("get put");
    await this.medinfoService.updateZhongyoo(id, updateData);
    return { message: 'success' }
  }
}
